var nodemailer=require("nodemailer");
var _ljs=require("../mmlog").root("[channel/mail.js]");
var Base64 = require('../../client/common/vendor/base64.min').Base64;

var mailConf=null; 
var transporter = null;

module.exports={
	
	init:function(config){
		mailConf=config;
		transporter=nodemailer.createTransport(mailConf);
	},
	
	/**
	 * 邮件发送接口
	 * @param {Object} data to:"address," subject:"", text:"",html:"" attachments:[{filename:'',path:''}]
	 * @param {Object} callback
	 */
	send:function(data,callback){
		data.from=mailConf.auth.user;
		transporter.sendMail(data,function(error,info){
			if(error){
				_ljs.error("发送邮件失败:\n",error);
				callback && callback(-1);
			}else{
				callback && callback(info);
				_ljs.info("发送邮件成功:",info.response);				
			}
		});
	}
	
}

